/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package snmpapplication.utils;

import java.awt.Color;
import java.awt.Component;
import javax.swing.BorderFactory;
import javax.swing.DefaultListCellRenderer;
import javax.swing.JList;
import snmpapplication.beans.ManagedDevice;

/**
 * Class used to custom render the list of managed devices
 * @author APetcu
 */
public class ListRenderer extends DefaultListCellRenderer {

    @Override
    public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
        Component c = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);

        ManagedDevice md = (ManagedDevice) value;

        // Depending of the reachability of the device the cell will have a 
        // coresponding color
        if (md.getIsReachable() == Constante.SNMP_REACH) {
            c.setBackground(Color.green);
            BorderFactory.createLineBorder(Color.black, 2);
        } else {
            if (md.getIsReachable() == Constante.PING_REACH) {
                c.setBackground(Color.yellow);
                BorderFactory.createLineBorder(Color.black, 2);
            } else {
                c.setBackground(Color.red);
                BorderFactory.createLineBorder(Color.black, 2);
            }
        }
        return c;
    }
}
